<?php



namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Api\BasicController;
use App\Models\UsersExperience;
use Jiannei\Response\Laravel\Support\Facades\Response;

class ExperienceController extends BasicController
{

    /**
     * @api {post }  /user/experience/add
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource|\Jiannei\Response\Laravel\JsonResource|\Jiannei\Response\Laravel\JsonResponse
     */

    public function add(){
        $data = $this->data(['time_interval', 'subject']);
        $data['user_id'] = $this->uid();
        $result = UsersExperience::insert($data);
        return Response::success($result);

    }
    /**
     * @api {post }  /user/experience/update
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource|\Jiannei\Response\Laravel\JsonResource|\Jiannei\Response\Laravel\JsonResponse
     */
    public function update(){
        $data = $this->data(['time_interval', 'subject']);
        $where['id'] = $this->request->input('id');
        $result = UsersExperience::where($where)->update($data);
        return Response::success($result);

    }

    public function list(){
        $data['user_id'] = $this->uid();
        $result = UsersExperience::where($data)->orderByDesc('id')->get();
        return Response::success($result);
    }

    public function del(){
        $id=$this->request->input('id');
        $result = UsersExperience::where(['id'=>$id,'user_id'=>$this->uid()])->delete();
        return Response::success($result);
    }

}
